package ll.sms.dao;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import ll.sms.db.SqlBuilder;
import ll.sms.exceptions.SmsDBException;
import ll.sms.pojo.SmsSuggest;
import ll.sms.util.SmsUtil;
import ll.sms.web.SmsAppContainer;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class SmsSuggestDAO extends BaseDAO {
	private static Log log = LogFactory.getLog(SmsSuggestDAO.class);

	public void saveSuggest(SmsSuggest Suggest) {
		/*
		private String suname;
		private String stype;
		private String scontent;
		private Date saddtime;
*/
		try {
			String sql = SqlBuilder.getSql("SAVE_SUGGEST",
					Suggest.getSid(),
					Suggest.getSuname(),
					Suggest.getStype(),
					Suggest.getScontent(),
					Suggest.getSaddtime()//DATE
					);
			this.update(sql, getConnection());
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e);
			throw new SmsDBException(e);

		}

	}

	public int deleteSuggestByProperties(String fieldName, Object value) {
		try {
			String sql = SqlBuilder.getSql("DELETE_SUGGEST", SqlBuilder.toPropertyString(fieldName),
					value);

		
			return this.update(sql, getConnection());
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e);
			throw new SmsDBException(e);

		}
	}

	public List<SmsSuggest> findAllSuggests(){
		 try {
			 String sql = SqlBuilder.getSql("QUERY_ALL_SUGGEST");
			 return this.searchToBeanList(getConnection(), SmsSuggest.class, sql);
		 } catch (Exception e) {
		 e.printStackTrace();
		 log.error(e);
		 throw new SmsDBException(e);

		 }
	}

}
